home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / ixemul-complete / ixemul / utils / cli.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-18  |  9.5 KB  |  304 lines

  1. /*
  2.     Ixprefs v.2.3--ixemul.library configuration program
  3.     Copyright © 1995,1996 Kriton Kyrimis
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include <dos/dos.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include "getopt.h"
  24.  
  25. extern void defaults(void), use(void), save(void), last_saved(void);
  26. extern int ixprefsabout(void);
  27.  
  28. extern int translateslash, membuf, watcher, redzone, blocks, cases, suppress,
  29.        amigawildcard, noflush, ignoreenv, networking, enforcerhit,
  30.        profilemethod;
  31.  
  32. void
  33. usage(char *prog)
  34. {
  35.   printf("Usage: %s [OPTION]...\n\nOptions:\n", prog);
  36.   printf("-a 1, --allow-amiga-wildcard\n");
  37.   printf("  accept AmigaOS wildcard notation\n");
  38.   printf("-a 0, --no-allow-amiga-wildcard\n");
  39.   printf("  do not accept AmigaOS wildcard notation\n");
  40.   printf("-s 1, --unix-pattern-matching-case-sensitive\n");
  41.   printf("  use case sensitive UNIX pattern matching\n");
  42.   printf("-s 0, --no-unix-pattern-matching-case-sensitive\n");
  43.   printf("  use case insensitive UNIX patter matching\n");
  44.   printf("-/ 1, --translate-slash\n");
  45.   printf("  translate /foo -> foo: and a//b -> a/b\n");
  46.   printf("-/ 0, --no-translate-slash\n");
  47.   printf("  do not translate /foo -> foo: and a//b -> a/b\n");
  48.   printf("-m N, --membuf-limit N\n");
  49.   printf("  files up to N bytes are cached in memory\n");
  50.   printf("-w 1, --watch-stack\n");
  51.   printf("  enable stack watcher\n");
  52.   printf("-w 0, --no-watch-stack\n");
  53.   printf("  disable stack watcher\n");
  54.   printf("-r N, --red-zone-size N\n");
  55.   printf("  set red zone size to N bytes\n");
  56.   printf("-b N, --fs-buf-factor N\n");
  57.   printf("  N physical blocks map into 1 logical (stdio) block\n");
  58.   printf("-i 1, --ignore-global-env\n");
  59.   printf("  ignore global environment (ENV:)\n");
  60.   printf("-i 0, --no-ignore-global-env\n");
  61.   printf("  do not ignore global environment (ENV:)\n");
  62.   printf("-e 1, --enforcer-hit\n");
  63.   printf("  generate Enforcer hit when a trap occurs\n");
  64.   printf("-e 0, --no-enforcer-hit\n");
  65.   printf("  do not generate Enforcer hit when a trap occurs\n");
  66.   printf("-v 0, --insert-disk-requester\n");
  67.   printf("  suppress the \"Insert volume in drive\" requester\n");
  68.   printf("-v 1, --no-insert-disk-requester\n");
  69.   printf("  do not suppress the \"Insert volume in drive\" requester\n");
  70.   printf("-f 0, --flush-library\n");
  71.   printf("  prevent ixemul.library from being flushed from memory\n");
  72.   printf("-f 1, --no-flush-library\n");
  73.   printf("  do not prevent ixemul.library from being flushed from memory\n");
  74.   printf("-n 0, --auto-detect\n");
  75.   printf("  set networking support to auto detect\n");
  76.   printf("-n 1, --no-networking\n");
  77.   printf("  turn off networking support\n");
  78.   printf("-n 2, --as225\n");
  79.   printf("  use AS225 networking support\n");
  80.   printf("-n 3, --amitcp\n");
  81.   printf("  use AmiTCP networking support\n");
  82.   printf("-p 0, --profile-program\n");
  83.   printf("  profile the program only\n");
  84.   printf("-p 1, --profile-task\n");
  85.   printf("  profile while the task is running\n");
  86.   printf("-p 2, --profile-always\n");
  87.   printf("  always profile your program\n");
  88.   printf("-d, --default\n");
  89.   printf("  reset settings to defaults (other options are ignored)\n");
  90.   printf("-L, --last-saved\n");
  91.   printf("  reset settings from configuration file (other options are ignored)\n");
  92.   printf("-S, --save\n");
  93.   printf("  save new configuration\n");
  94.   printf("-R, --report\n");
  95.   printf("  display new configuration\n");
  96.   printf("-V, --version\n");
  97.   printf("  display program version information (other options are ignored)\n");
  98.   printf("-h, --help\n");
  99.   printf("  display this text\n");
  100.   printf("\nUse no arguments to get the GUI\n");
  101. }
  102.  
  103. void
  104. display_config(void)
  105. {
  106.   printf((amigawildcard ? "A" : "Do not a"));
  107.   printf("ccept AmigaOS wildcard notation,\n");
  108.   printf("Case ");
  109.   printf((cases ? "" : "in"));
  110.   printf("sensitive UNIX pattern matching,\n");
  111.   printf((translateslash ? "" : "do not "));
  112.   printf("translate /, ");
  113.   printf("membuf size = %d,\n", membuf);
  114.   printf("stack watcher is ");
  115.   printf((watcher ? "en" : "dis"));
  116.   printf("abled, red zone size = %d,\n", redzone);
  117.   printf("%d physical block", blocks);
  118.   printf(((blocks == 1) ? "" : "s"));
  119.   printf(" build");
  120.   printf(((blocks == 1) ? "s" : ""));
  121.   printf(" one logical block (for stdio),\n");
  122.   printf((ignoreenv ? "" : "do not "));
  123.   printf("ignore global environment (ENV:),\n");
  124.   printf((enforcerhit ? "" : "do not "));
  125.   printf("generate Enforcer hit when a trap occurs,\n");
  126.   printf((suppress ? "" : "do not "));
  127.   printf("suppress the \"Insert volume in drive\" requester,\n");
  128.   printf("use ");
  129.   switch (networking)
  130.   {
  131.     case 0: printf("auto-detect"); break;
  132.     case 1: printf("no"); break;
  133.     case 2: printf("AS225"); break;
  134.     case 3: printf("AmiTCP"); break;
  135.     default: printf("unknown"); break;
  136.   }
  137.   printf(" networking support,\n");
  138.   printf("profile ");
  139.   switch (profilemethod)
  140.   {
  141.     case 0: printf("your program,\n"); break;
  142.     case 1: printf("while your task is running,\n"); break;
  143.     case 2: printf("always,\n"); break;
  144.   }
  145.   printf((noflush ? "" : "do not "));
  146.   printf("prevent ixemul.library from being flushed from memory.\n");
  147. }
  148.  
  149. int
  150. parse_cli_commands(int argc, char *argv[])
  151. {
  152.   int c, error = 0, status;
  153.   static int reset_defaults = 0, save_config = 0, help = 0, report = 0,
  154.          last = 0, version = 0;
  155.  
  156.   while (1) {
  157.     int option_index = 0;
  158.     static struct option long_options[] = {
  159.       {"insert-disk-requester", 0, &suppress, 0},        /* -v */
  160.       {"no-insert-disk-requester", 0, &suppress, 1},
  161.       {"unix-pattern-matching-case-sensitive", 0, &cases, 1},    /* -s */
  162.       {"no-unix-pattern-matching-case-sensitive", 0, &cases, 0},
  163.       {"watch-stack", 0, &watcher, 1},                /* -w */
  164.       {"no-watch-stack", 0, &watcher, 0},
  165.       {"translate-slash", 0, &translateslash, 1},        /* -/ */
  166.       {"no-translate-slash", 0, &translateslash, 0},
  167.       {"allow-amiga-wildcard", 0, &amigawildcard, 1},        /* -a */
  168.       {"no-allow-amiga-wildcard", 0, &amigawildcard, 0},
  169.       {"flush-library", 0, &noflush, 0},            /* -f */
  170.       {"no-flush-library", 0, &noflush, 1},
  171.       {"ignore-global-env", 0, &ignoreenv, 1},            /* -i */
  172.       {"no-ignore-global-env", 0, &ignoreenv, 0},
  173.       {"enforcer-hit", 0, &enforcerhit, 1},            /* -e */
  174.       {"no-enforcer-hit", 0, &enforcerhit, 0},
  175.       {"auto-detect", 0, &networking, 0},            /* -n */
  176.       {"no-networking", 0, &networking, 1},
  177.       {"as225", 0, &networking, 2},
  178.       {"amitcp", 0, &networking, 3},
  179.       {"auto-detect", 0, &networking, 0},
  180.       {"no-networking", 0, &networking, 1},
  181.       {"as225", 0, &networking, 2},
  182.       {"profile-program", 0, &profilemethod, 0},        /* -p */
  183.       {"profile-task", 0, &profilemethod, 1},
  184.       {"profile-always", 0, &profilemethod, 2},
  185.       {"membuf-limit", 1, 0, 'm'},                /* -m */
  186.       {"red-zone-size", 1, 0, 'r'},                /* -r */
  187.       {"fs-buf-factor", 1, 0, 'b'},                /* -b */
  188.       {"default", 0, &reset_defaults, 1},            /* -d */
  189.       {"save", 0, &save_config, 1},                /* -S */
  190.       {"report", 0, &report, 1},                /* -R */
  191.       {"last-saved", 0, &last, 1},                /* -L */
  192.       {"version", 0, &version, 1},                /* -V */
  193.       {"help", 0, &help, 1},                    /* -h */
  194.       {0, 0, 0, 0}
  195.     };
  196.     c = getopt_long (argc, argv, "v:s:x:w:a:/:f:i:e:m:n:r:b:p:dShRLV",
  197.                  long_options, &option_index);
  198.     if (c == EOF) {
  199.       break;
  200.     }
  201.     switch (c) {
  202.       case 0:
  203.     break;
  204.       case 'v':
  205.     suppress = (atoi(optarg) ? 0 : 1);
  206.     break;
  207.       case 's':
  208.     cases = (atoi(optarg) ? 1 : 0);
  209.     break;
  210.       case 'w':
  211.     watcher = (atoi(optarg) ? 1 : 0);
  212.     break;
  213.       case 'a':
  214.     amigawildcard = (atoi(optarg) ? 1 : 0);
  215.     break;
  216.       case '/':
  217.     translateslash = (atoi(optarg) ? 1 : 0);
  218.     break;
  219.       case 'f':
  220.         noflush = (atoi(optarg) ? 0 : 1);
  221.     break;
  222.       case 'i':
  223.         ignoreenv = atoi(optarg);
  224.     break;
  225.       case 'e':
  226.         enforcerhit = atoi(optarg);
  227.     break;
  228.       case 'm':
  229.     membuf = atoi(optarg);
  230.     break;
  231.       case 'n':
  232.     networking = atoi(optarg);
  233.     break;
  234.       case 'p':
  235.     profilemethod = atoi(optarg);
  236.     break;
  237.       case 'r':
  238.     redzone = atoi(optarg);
  239.     break;
  240.       case 'b':
  241.     blocks = atoi(optarg);
  242.     break;
  243.       case 'd':
  244.     reset_defaults = 1;
  245.     break;
  246.       case 'S':
  247.     save_config = 1;
  248.     break;
  249.       case 'h':
  250.         help = 1;
  251.     break;
  252.       case 'R':
  253.         report = 1;
  254.     break;
  255.       case 'L':
  256.         last = 1;
  257.     break;
  258.       case 'V':
  259.         version = 1;
  260.     break;
  261.       default:
  262.     error = 1;
  263.     break;
  264.     }
  265.   }
  266.   if (optind < argc) {
  267.     error = 1;
  268.   }
  269.   if (error) {
  270.     fprintf(stderr, "\n");
  271.     usage(argv[0]);
  272.     status = RETURN_FAIL;
  273.   }else{
  274.     status = RETURN_OK;
  275.     if (version) {
  276.       (void)ixprefsabout();
  277.     }else{
  278.       if (help) {
  279.     usage(argv[0]);
  280.       }else{
  281.     if (last) {
  282.       if (reset_defaults) {
  283.         fprintf(stderr,
  284.   "--last-saved and --default specified together.  --default ignored.\n");
  285.       }
  286.       last_saved();
  287.     }
  288.     if (reset_defaults) {
  289.       defaults();
  290.     }
  291.     if (save_config) {
  292.       save();
  293.     }else{
  294.       use();
  295.     }
  296.     if (report) {
  297.       display_config();
  298.     }
  299.       }
  300.     }
  301.   }
  302.   return status;
  303. }
  304.